<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>class类继承-多重继承</title>
</head>

<body>
  <script>
    /* 
      extends的右侧是一个表达式，使得子类的继承更加灵活，能动态的选择父类
    */
    
    function getPeople(gender) {
      return gender === 1 ? Man : Woman
    }
    class Man {}
    class Woman {}
    class Person1 extends getPeople(1) {}
    var person1 = new Person1()
    console.log(person1 instanceof Man)
    console.log(person1 instanceof Woman)

    /* 
      多重继承
      将多个对象或者类合并成一个，间接实现多重继承的作法叫作类的模板，也叫作抽象子类或mixin（混合）
    */

    function mixin(...objects) {
      function middle() {}
      Object.assign(middle.prototype, ...objects)
      return middle
    }

    var man = {
      getMan() {
        return "男"
      }
    }

    var woman = {
      getWoman() {
        return "女"
      }
    }

    class Person2 extends mixin(man, woman) {}
    var person2 = new Person2()
    console.log(person2.getMan())
    console.log(person2.getWoman())
  </script>
</body>

</html>